/* Copyright (C) 2007-2010 Open Information Security Foundation
 *
 * You can copy, redistribute or modify this Program under the terms of
 * the GNU General Public License version 2 as published by the Free
 * Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * \file
 *
 * \author Prabhakaran Kasinathan <kasinthan@ismb.it>
 */

#ifndef __DECODE_IEEE802154_H__
#define __DECODE_IEEE802154_H__

#define IEEE802154_HEADER_LEN           3 // check whether this is true
#define IEEE802154_MAX_FRAME_LEN        127


/* IEEE802154 types -- taken from wireshark decoders */
#define IEEE802154_BEACON				0X0000
#define IEEE802154_DATA					0x0001
#define IEEE802154_ACK					0x0002
#define IEEE802154_COMMAND				0x0003

/* Address Mode Definitions */
#define IEEE802154_FCF_ADDR_NONE            0x0000
#define IEEE802154_FCF_ADDR_SHORT           0x0002
#define IEEE802154_FCF_ADDR_EXT             0x0003

/*  Bit-masks for the FCF */
#define IEEE802154_FCF_TYPE_MASK            0x0007  /* Frame Type Mask */
#define IEEE802154_FCF_SEC_EN               0x0008
#define IEEE802154_FCF_FRAME_PND            0x0010
#define IEEE802154_FCF_ACK_REQ              0x0020
#define IEEE802154_FCF_INTRA_PAN            0x0040  /* known as PAN ID Compression in IEEE 802.15.4-2006 */
#define IEEE802154_FCF_DADDR_MASK           0x0C00  /* destination addressing mask */
#define IEEE802154_FCF_VERSION              0x3000
#define IEEE802154_FCF_SADDR_MASK           0xC000  /* source addressing mask */

/*
typedef enum {
    SECURITY_LEVEL_NONE = 0x00,
    SECURITY_LEVEL_MIC_32 = 0x01,
    SECURITY_LEVEL_MIC_64 = 0x02,
    SECURITY_LEVEL_MIC_128 = 0x03,
    SECURITY_LEVEL_ENC = 0x04,
    SECURITY_LEVEL_ENC_MIC_32 = 0x05,
    SECURITY_LEVEL_ENC_MIC_64 = 0x06,
    SECURITY_LEVEL_ENC_MIC_128 = 0x07
} ieee802154_security_level;
*/

typedef struct Ieee802154Hdr_ {
    uint16_t  ieee802154_fcf;
    uint16_t   ieee802154_seq;
    uint16_t  ieee802154_dstpan;
    uint16_t  ieee802154_dstadd;
    uint16_t  ieee802154_srcadd;
     
    } Ieee802154Hdr;


/* old editing aug 21
typedef struct Ieee802154Hdr_ {
    uint16_t ieee802154_fcf;
    uint8_t ieee802154_seq;
    uint8_t  ieee802154_dstpan1;
    uint8_t  ieee802154_dstpan2;
    uint8_t  ieee802154_dstadd1;
    uint8_t  ieee802154_dstadd2;
    uint8_t  ieee802154_srcadd1;
    uint8_t  ieee802154_srcadd2;
     
    } Ieee802154Hdr;

*/

/* Key used by the short address hash table. */
typedef struct Ieee802154Vars_ {
 
   uint16_t      pan;
    uint16_t     saddr;
    uint16_t     daddr;
} Ieee802154Vars;


#define IEEE802154_GET_RAW_FRAME_TYPE(ieeeh)  	((ieeeh)->ieee802154_fcf & IEEE802154_FCF_TYPE_MASK)
#define IEEE802154_GET_RAW_DSTPAN(ieeeh) 	((ieeeh)->ieee802154_dstpan)
#define IEEE802154_GET_RAW_DSTADD(ieeeh)  	(((ieeeh)->ieee802154_fcf & IEEE802154_FCF_DADDR_MASK) >>10)
#define IEEE802154_GET_RAW_SRCADD(ieeeh)  	(((ieeeh)->ieee802154_fcf & IEEE802154_FCF_SADDR_MASK) >>14)
    //fa_d = ((p->ieeeh->ieee802154_fcf) & IEEE802154_FCF_DADDR_MASK);


#define IEEE802154_GET_FRAME_TYPE(p) IEEE802154_GET_RAW_FRAME_TYPE((p)->ieeeh)
#define IEEE802154_GET_DSTPAN(p) IEEE802154_GET_RAW_DSTPAN((p)->ieeeh)
#define IEEE802154_GET_DSTADD(p) IEEE802154_GET_RAW_DSTADD((p)->ieeeh)
#define IEEE802154_GET_SRCADD(p) IEEE802154_GET_RAW_SRCADD((p)->ieeeh)


#endif /* __DECODE_IEEE802154_H__ */


